package cn.gjxblog.mq.custom;

import cn.gjxblog.mq.utils.ConnectionUtils;
import com.rabbitmq.client.*;

import java.io.IOException;


/**
 * @author gjx
 * @version v1.0
 * @Description
 * @date 2019/7/4 11:48
 */
public class Producer {
    public static void main(String[] args) throws Exception {

        //1 创建连接
        Connection connection = ConnectionUtils.getConnection();

        //2 通过connection创建channel
        Channel channel = connection.createChannel();

        //3 通过channel发送数据
        String exchangeName = "test_custom_exchange";
        String routingKey = "custom.save";
        String msg = "Hello RabbitMQ!";

        for (int i = 0; i < 5; i++) {
            //mandatory: 如果为true,则监听器会接收到路由不可达的信息，然后进行后续处理，如果为false,那么broker端字典删除该消息
            channel.basicPublish(exchangeName,routingKey,true,null,msg.getBytes());
        }

    }
}
